//
//  ViewController.m
//  02-LaGouRegisterHomeWork
//
//  Created by 曹曹 on 16/7/15.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "ViewController.h"
#import "LoginView.h"
#import "RegisterViewController.h"
#import "VertificateViewController.h"
#import "LabelButton.h"

#define SCREEN_WIDTH self.view.frame.size.width

@interface ViewController ()
@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) UIImageView *logoImageView;
@property (nonatomic, strong) UIButton *loginButton;
@property (nonatomic, strong) UIButton *forgetPasswordButton;
@property (nonatomic, strong) UIButton *registerButton;
@property (nonatomic, strong) UIButton *casualButton;
@property (nonatomic, strong) LoginView *logins;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setBackgroundImage];
    [self setLogoImage];
    _logins = [[LoginView alloc] initWithFrame:CGRectMake(14, 350, SCREEN_WIDTH - 28, 89)
                                               imageUser:@"icon_username"
                                           imagePassword:@"icon_password"
                                         placeHolderUser:@"请输入已验证手机号或邮箱"
                                 placeHolderDownPassword:@"请输入密码"];
    [self.view addSubview:_logins];
    [self createLoginButton];
    [self createForgetPasswordButton];
    [self createRegisterButton];
    [self createLines];
    [self createCasualGoButton];
    // NSString *blog = @"http://www.jianshu.com/p/1ec082980b22";
}
#pragma mark - 背景
- (void)setBackgroundImage {
    _backgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"welcome_2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self.view addSubview:_backgroundImageView];
    _backgroundImageView.frame = self.view.frame;
}
#pragma mark - LOGO
- (void)setLogoImage {
    _logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_lagou"]];
    [_backgroundImageView addSubview:_logoImageView];
    _logoImageView.frame = CGRectMake(0, 0, 92, 148);
    _logoImageView.center = CGPointMake(SCREEN_WIDTH / 2, 240);
}
#pragma mark - 登录按钮
- (void)createLoginButton {
    LabelButton *loginButton = [[LabelButton alloc] initWithFrame:CGRectMake(14, 450, SCREEN_WIDTH - 28, 44)
                                                            title:@"登录"
                                                  backgroundColor:[UIColor colorWithRed:0.01 green:0.81 blue:0.53 alpha:1.00]
                                                        textColor:[UIColor whiteColor]
                                                           target:self
                                                           action:@selector(handleLoginButton:)];
    loginButton.layer.cornerRadius = 5;
    [self.view addSubview:loginButton];
}
#pragma mark - 忘记密码按钮
- (void)createForgetPasswordButton {
    LabelButton *forgetPasswordButton = [[LabelButton alloc] initWithFrame:CGRectMake(14, 505, 70, 44)
                                                                     title:@"忘记密码"
                                                           backgroundColor:nil
                                                                 textColor:[UIColor whiteColor]
                                                                    target:self
                                                                    action:@selector(handleForgetPassword:)];
    [self.view addSubview:forgetPasswordButton];
}
#pragma mark - 注册拉勾按钮
- (void)createRegisterButton {
    LabelButton *registerButton = [[LabelButton alloc] initWithFrame: CGRectMake(0, 0, 150, 44)
                                                               title:@"现在注册拉勾"
                                                     backgroundColor:nil
                                                           textColor:[UIColor colorWithRed:0.01 green:0.64 blue:0.49 alpha:1.00]
                                                              target:self
                                                              action:@selector(modalView:)];
    registerButton.center = CGPointMake(SCREEN_WIDTH / 2, 570);
    [self.view addSubview:registerButton];
}
#pragma mark - 细线
- (void)createLines {
    UIView *viewOfLineLeft = [[UIView alloc] initWithFrame:CGRectMake(14, 600, SCREEN_WIDTH / 2 - 30, 1)];
    UIView *viewOfLineRigt = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 14, 600, SCREEN_WIDTH / 2 - 30, 1)];
    viewOfLineLeft.backgroundColor = [UIColor whiteColor];
    viewOfLineRigt.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewOfLineLeft];
    [self.view addSubview:viewOfLineRigt];
    UILabel *labelOfOr = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
    labelOfOr.center = CGPointMake(SCREEN_WIDTH / 2, 600);
    labelOfOr.text = @"or";
    labelOfOr.textAlignment = NSTextAlignmentCenter;
    labelOfOr.textColor = [UIColor whiteColor];
    [self.view addSubview:labelOfOr];
}
#pragma mark -随便逛逛
- (void)createCasualGoButton {
    LabelButton *casualButton = [[LabelButton alloc] initWithFrame:CGRectMake(0, 0, 100, 44) title:@"随便逛逛>" backgroundColor:nil textColor:[UIColor whiteColor] target:self action:nil];
    casualButton.center = CGPointMake(SCREEN_WIDTH / 2, 650);
    [self.view addSubview:casualButton];
}
#pragma mark - 点击空杯回收键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
#pragma mark - 模态推出界面
- (void)modalView:(UIButton *)button {
    RegisterViewController *registerViewController = [[RegisterViewController alloc] init];
    [self presentViewController:registerViewController animated:YES completion:nil];
}
#pragma mark - 登录按钮点击事件
- (void)handleLoginButton:(UIButton *)button {
    [self.view endEditing:YES];
}
#pragma mark - 忘记密码点击事件
- (void)handleForgetPassword:(UIButton *)button {
    VertificateViewController *vertificateViewController = [[VertificateViewController alloc] init];
    [self presentViewController:vertificateViewController animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
